// Run.java
//
// Starts the game up basically.

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;

public class Run extends JFrame
{
    // The world in-game
    private static World w = new World();
    private static Run f;

    public Run(String s)
    {
        super(s);
    }

    // Creates the JFrame, generates the world, and gets the game ready to go
    public static void main(String[] args)
    {
        f = new Run("Test Build 1");
        
        // Listeners
        f.addWindowListener(new WindowAdapter()
	{
            public void windowClosing(WindowEvent e)
            {
                System.exit(0);
            }
        });
        f.addKeyListener(new KeyListener()
        {
            public void keyTyped(KeyEvent e)
            {
                char location = e.getKeyChar();
                if (location == '.')
                {
                    f.tick();
                }
            }

            public void keyReleased(KeyEvent e)
            {
            }

            public void keyPressed(KeyEvent e)
            {
            }
        });
        //End Listeners

        w.generate(30, 23);

        f.pack();
        f.setSize(new Dimension(736, 590));
	f.setVisible(true);
    }

    // Causes everything in the World to tick, repaints the JFrame to show changes
    public void tick()
    {
        w.tick();
	f.repaint();
    }

    // A method overridden in order to allow all the Tiles to show up on-screen.
    public void paint(Graphics g)
    {
        w.display(g);
    }
}